<template>
	<view class="distributionDetails">
		<view class="cardDetail flex-column-between">
			<view class="font-weight_bold">
				当前余额{{currency_name}}
			</view>
			<view class="flex-between" v-if="userinfoOj">
				<view style="color: #A265FC;;font-size: 54rpx;;" class="">
					{{userinfoOj.balance}}
				</view>
				<view class="recharge flex" @click="withdrawal(isAndroid)">
                     {{isAndroid?'充值':'联系客服'}}
				</view>
			</view>
			<view style="color: rgb(117, 117, 117);" v-if="myTeam">
				<view style="color: rgb(117, 117, 117);" v-if="myTeam">
					<text class="margin-right_16rpx">今日获得 {{myTeam.today_income+'余额('+currency_name+')'}}</text>
					<text>累计获得 {{myTeam.total_income+'余额('+currency_name+')'}}</text>
				</view>
			</view>
		</view>
	<!-- 	<view class="flex-between margin_40rpx_0 " style="padding: 0 15rpx;">
			<view class="all flex">
				全部
			</view>
			<view class="month">
			
			</view>
		</view> -->
		<!-- 明细列表 -->
		<mescroll-body ref="mescrollRef" :height="windowHeight+'rpx'" @init="mescrollInit" @down="downCallback"
			@up="upCallback" :up="upOption" :down="downOption">
			<block v-for="(item,index) in list" :key="index">
				<view class="detailedList">
					<view class="flex-between margin-bottom_20rpx"> 
						<view class="font-weight_bold" >
							{{orderStatusFn(item.operation_source)}}
						</view>	
						<view style="color: #A265FC;" class="font-weight_bold">
							{{item.amount_direction==1?'+':'-'}}{{item.amount +(item.amount_type==1?' 余额('+currency_name+')':' 收益('+currency_name+')')}}
						</view>
					</view>
					<view class="flex-between" style="color: rgb(117, 117, 117);;">
						<view class="flex-column-start">
							<text >赠送{{currency_name}}:{{item.gifts_amount}}</text>
							<text v-if="item.amount_type==1" style="margin-top: 5rpx;">优惠折扣:{{item.ratio=='0.00'?'0.00':100-Number(item.ratio)}}%</text>
							<text v-if="item.amount_type==2" style="margin-top: 5rpx;">优惠折扣:{{item.ratio}}%</text>
						</view>
						<view class="flex-column-end" style="">
							<view class="">
								{{item.amount_type==1?'余额变动':'收益变动'}}
							</view>
							<view class="">
								<text>{{item.create_time}}</text>
							</view>
						</view>
					</view>
				</view>
			</block>
		</mescroll-body>
	</view>
</template>

<script>
	export default {
		components: {

		},
		data() {
			const currentDate = this.getDate({
				format: true
			});
			return {
				currency_name:uni.getStorageSync("system").currency_name,
				userInfo: uni.getStorageSync("userInfo"),
				date: null,
				tabIndex: 4,
				currentTime: '2',
				navIndex: 0,
				searchVal: '',
				tabList: [{
					name: '直推粉丝',
					id: '1' //null
				}, {
					name: '间推粉丝',
					id: '2' //null
				}, ],
				yeartime: currentDate.split('-')[0],
				//选择的月份
				monthtime: currentDate.split('-')[1],
				//选择的天数
				daytime: currentDate.split('-')[2],
				token: uni.getStorageSync('login').token,
				downOption: {
					auto: true
				},
				// 上拉配置项
				upOption: {
					auto: false
				},
				token: uni.getStorageSync('login').token,
				windowHeight: '',
				list: [],
				myTeam: null,
				userinfoOj: null,
				isAndroid:true,
				amount_type:1
			}
		},
		onLoad(options) {
			
		    this.amount_type=options.amount_type
			console.log(this.amount_type)
			this.userInformation()
			this.init()
			wx.getSystemInfo({
				success: (res) => {
					let platform = res.system;
			        this.windowHeight = res.windowHeight * 2 - 800;
					if (platform.indexOf('Android') !== -1) {
						this.isAndroid = true
			
						console.log('用户使用安卓设备');
			
					} else if (platform.indexOf('iOS') !== -1) {
						this.isAndroid = false
						// uni.showModal({
						// 	title: '提示',
						// 	content: '是否跳转到联系我们页面',
						// 	success: async (res) => {
						// 		if (res.confirm) {
						//              this.$sun.navGo('/pagesA/personalCenter/contactUs')
			
						// 		} else if (res.cancel) {
			
						// 		}
						// 	}
						// });
						console.log('用户使用苹果设备');
					}
				}
			});
		},
		onShow() {
			this.userInformation()
			this.mescroll?.resetUpScroll();

		},
		computed: {

			// 订单状态 '1 待审核 2 上架中 3 下架 4 驳回',
			orderStatusFn: function() {
				return function(status) {
					// 1 待接单 2 接单中 3 完成 4 已结算 4拒绝订单
					let orderStatus = '';

					orderStatus =
						status == 0 ? '充值 ' : status == 1 ? '充值' : status == 2 ? '加入搭子' : status == 3 ? '退出搭子' :
						status == 4 ? '搭子完成收益' : status == 5 ? '提现' : status == 6 ? '下单服务' : status == 7 ? '退出服务' 
						:status == 8?'服务完成':status == 9?'搭子分佣':status == 10?'服务分佣':status == 11?'退出搭子补偿'
						:status == 12?'加入社区扣除':status == 13?'社区收益':status == 14?'社区分佣':status == 16?'后台添加'+this.currency_name:status == 17?'后台扣除'+this.currency_name
						:status == 18?'查看手机号':status == 19?'退回申请手机号':status == 20?'搭子置顶':status == 21?'服务置顶':status == 22?'用户拉新(合伙人)':status == 23?'充值返佣'
						:status == 24?'购买vip佣金':status == 25?'聊天扣费':status == 26?'填写资料':status == 27?'新用户注册':status == 28?'用户拉新':status == 29?'手机认证'
						:status == 30?'实名认证':'收益转余额'
						

					return orderStatus;
				};
			},
		},
		methods: {
			
			async init(){

				const res = await this.$http.post({
					url: this.$api.income,
					data: {
				         
						
					},
					headers: {
						'Authorization': this.userInfo.token
					}
				
				})
				console.log(res)
				if (res.code == 0) {
					// 跳转到登录页面
			          this.myTeam=res.data
					
					  
					  console.log(res.data)
				
				} else {
					
					this.$sun.toast(res.message, 'none')
				}
			},
			async templateTpo() {
				wx.requestSubscribeMessage({
					tmplIds: JSON.parse(JSON.stringify(uni.getStorageSync("messageListTemplate"))),
					success: res => { //成功、
						if (res[Object.keys(res)[0]] == "accept") {
							console.log("成功订阅")
							// this.$sun.toast("成功订阅")
						} else {
							this.$sun.toast(
								"点击右上角的「...」按钮，找到「订阅消息」相关选项，并设定为「接收」状态方可再次订阅")
				
							uni.showModal({
								title: "温馨提示",
								content: "点击右上角的「...」按钮，找到「订阅消息」相关选项，并设定为「接收」状态方可再次订阅"
							})
						}
					},
					fail: err => { //失败
						console.log(err)
						this.$sun.toast("订阅消息配置失败");
					}
				})
				
				
				
				// wx.getSetting({
				// 	success(res) {
				// 		console.log(res)
				// 		if (res.subscriptionsSetting) {
				// 			// 用户有pushSubscription对象
				// 			const pushSubscription = res.subscriptionsSetting['message.subscribe.send']
				// 			if (pushSubscription) {
				// 				// 用户已订阅
				// 				console.log('用户已订阅')
				// 				this.$sun.toast("用户已订阅")
				// 			} else {
				// 				wx.requestSubscribeMessage({
				// 					tmplIds: ['Y04lXw-tkuSAdFi77o5BPCJij1Z9fq7e4ZbIYidgm20'],
				// 					success: res => { //成功、
				// 						if (res[Object.keys(res)[0]] == "accept") {
				// 							console.log("成功订阅")
				// 							this.$sun.toast("成功订阅")
				// 						} else {
				// 							this.$sun.toast(
				// 								"点击右上角的「...」按钮，找到「订阅消息」相关选项，并设定为「接收」状态方可再次订阅")
			
				// 							uni.showModal({
				// 								title: "温馨提示",
				// 								content: "点击右上角的「...」按钮，找到「订阅消息」相关选项，并设定为「接收」状态方可再次订阅"
				// 							})
				// 						}
				// 					},
				// 					fail: err => { //失败
				// 						console.log("订阅消息配置失败")
				// 						this.$sun.toast("订阅消息配置失败");
				// 					}
				// 				})
						
				// 			}
				// 		} else {
				// 			this.$sun.toast("无法获取订阅状态")
				// 			// 用户没有pushSubscription对象，可能是微信版本过低或者用户未允许小程序获取该权限
				// 			console.log('无法获取订阅状态')
				// 		}
				// 	},
				// 	fail() {
				// 		// 获取设置失败的处理逻辑
				// 	}
				// })
			
			
			
			
			
			},
			withdrawal(isAndroid) {
				if(isAndroid){
					this.templateTpo()
					this.$sun.navGo('/pagesA/personalCenter/onlineRecharge')
				}else{
					this.$sun.navGo('/pagesA/personalCenter/contactUs')
				}
			},
			async userInformation() {
				const result = await this.$http.post({
					url: this.$api.userInfo,
					data: {
						
				
				
				
					},
					headers: {
						'Authorization': this.userInfo.token
					}
				
				})
				
				if (result.code == 0) {
					console.log('data', result.data);
					this.userinfoOj=result.data
					
					
				}else{
					this.$sun.toast(result.message, 'none')
				}
			},
			// 日期获取
			getDate(type) {
				const date = new Date();
				let year = date.getFullYear();
				let month = date.getMonth() + 1;
				let day = date.getDate();
				if (type === 'start') {
					year = year - 60;
				} else if (type === 'end') {
					year = year + 2;
				}
				month = month > 9 ? month : '0' + month;
				day = day > 9 ? day : '0' + day;

				return `${year}-${month}-${day}`;

			},

			bindDateChange(e) {


				this.createTime = e.detail.value
				this.date = e.target.value;
				/* 在上面声明变量，split是用来截取字段*/
				this.yeartime = this.date.split('-')[0];
				this.monthtime = this.date.split('-')[1];
				this.daytime = this.date.split('-')[2];


			},

			async upCallback(scroll) {

				const result = await this.$http.post({
					url: this.$api.amountLog,
					data: {
						page: scroll.num,
						limit: 10,
						amount_type:this.amount_type


					},
					headers: {
						'Authorization': this.userInfo.token
					}

				})
				if (result.code == 0) {
					console.log('地址管理列表', result);
					this.count = result.data.count
					this.mescroll.endByPage(result.data.list.length, this.$sun.pagingSum(result.data.count, 10));
					if (scroll.num == 1) this.list = [];
					this.list = this.list.concat(result.data.list);
					console.log('this.list', this.list, this.list.length);
				}
			},

		},
	
	}
</script>

<style lang="less" scoped>
	page {
		background: #f6f6f6;
		padding: 30rpx;
	}

	.distributionDetails {
		.cardDetail {
            margin-bottom: 20rpx;
			height: 260rpx;
			border-radius: 10rpx;

			background: rgb(255, 255, 255);
			padding: 40rpx;

			.recharge {
				width: 152rpx;
				height: 68rpx;
				border-radius: 200rpx;
				color: rgb(255, 255, 255);
				background: #A265FC;
			}
		}

		.all {
			width: 102rpx;
			height: 46rpx;
			border-radius: 10rpx;
			color: rgb(255, 255, 255);
			background: rgb(255, 0, 0);
		}

		.detailedList {

			// height: 152rpx;
			border-radius: 10rpx;
			padding: 20rpx;
			background: rgb(255, 255, 255);
		}
	}
</style>